<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>GeoLocation API演示程序</title>
    <script type="text/javascript">
        function startgps()
        {
            var gps = navigator.geolocation;
            if (gps)
            {
                gps.getCurrentPosition(showgps,
                    function(error)
                    {
                        alert("Got an error, code: " + error.code + " message: "+ error.message);
                    },
                    {maximumAge: 10000}); // 这里设置超时为10000毫秒，即10秒
            }
            else
            {
                showgps();
            }
        }

        function showgps(position)
        {
            if (position)
            {
                var latitude = position.coords.latitude;
                var longitude = position.coords.longitude;
                alert("纬度: " + latitude + "\resource\n 经度: "+ longitude);
            }
            else
                alert("position is null");
        }
    </script>

</head>

<body>
<section class="ui-page ui-body-c ui-page-active" data-url="page1" id="page1" data-role="page">
    <header role="banner"    class="ui-bar-a ui-header" data-role="header">
        <h1 aria-level="1" role="heading"    tabindex="0" class="ui-title">GeoLocation API Demo</h1>
    </header>
    <div role="main" data-role="content" class="ui-content">
        <input type="button" value="我的位置" onclick="startgps()"/>
    </div>
    <footer role="contentinfo" class="ui-bar-a ui-footer" data-role="footer">
        <h1 aria-level="1" role="heading"    tabindex="0" class="ui-title">Allan Yan</h1>
    </footer>
</section>
</body>
</html>